package com.example.controller.weixiubaoyang;

import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.annotation.Log;
import com.example.common.result.Result;
import com.example.entity.dto.weixiubaoyang.*;
import com.example.entity.vo.weixiubaoyang.SelMaintainPlanListVo;
import com.example.entity.yifei.*;
import com.example.exception.CustomException;
import com.example.mapper.*;
import com.example.service.*;
import com.example.service.weixiubaoyang.RepairMaintainService;
import com.example.untils.BeanUtils;
import com.example.untils.SecurityUtils;
import com.example.untils.StringUtils;
import com.example.untils.TimeUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/api/repairMaintain")
@Api(tags = "维修and保养单接口")
public class RepairMaintainController {

    @Autowired
    private EqtteService eqtteService;
    @Autowired
    private EqtteMapper eqtteMapper;
    @Autowired
    private EqttfService eqttfService;
    @Autowired
    private EqttfMapper eqttfMapper;
    @Autowired
    private RepairMaintainService repairMaintainService;
    @Autowired
    private MaintainplanitemService maintainplanitemService;
    @Autowired
    private MaintainplanitemMapper maintainplanitemMapper;
    @Autowired
    private MaintainplanruleMapper maintainplanruleMapper;
    @Autowired
    private MaintainplanService maintainplanService;
    @Autowired
    private MaintainplanMapper maintainplanMapper;
    @Autowired
    private MaintainplangroupService maintainplangroupService;
    @Autowired
    private MaintainplangroupMapper maintainplangroupMapper;
    @Autowired
    private MaintainplangroupMaintainplanService maintainplangroupMaintainplanService;
    @Autowired
    private MaintainplangroupMaintainplanMapper maintainplangroupMaintainplanMapper;
    @Autowired
    private MaintainplanMaintainplanitemService maintainplanMaintainplanitemService;
    @Autowired
    private MaintainplanMaintainplanitemMapper maintainplanMaintainplanitemMapper;
    @Autowired
    private MaintainplanMaintainplanruleService maintainplanMaintainplanruleService;
    @Autowired
    private MaintainplanMaintainplanruleMapper maintainplanMaintainplanruleMapper;
    @Autowired
    private MaintainplangroupResourcegroupMapper maintainplangroupResourcegroupMapper;
    @Autowired
    private DscmaMapper dscmaMapper;

    @Log("保存计划项目（点检项目，保养项目，维修项目）")
    @ApiOperation("保存计划项目（点检项目，保养项目，维修项目）")
    @PostMapping("saveMaintainPlanItem")
    @DSTransactional
    public Result saveMaintainPlanItem(@RequestBody SaveMaintainPlanItemDto dto) {
        Maintainplanitem maintainplanitem = new Maintainplanitem();
        BeanUtils.copyPropertiesIgnoreCase(dto, maintainplanitem);
//        maintainplanitem.setMpiid();
        maintainplanitem.setMpicreator(SecurityUtils.getLoginUser().getUsername());
        maintainplanitem.setMpicreationtime(TimeUtils.getFullNowTime());
        maintainplanitemMapper.insert(maintainplanitem);
        return Result.success("计划项目保存成功");
    }

    @ApiOperation("查询计划项目（点检项目，保养项目，维修项目）")
    @PostMapping("selMaintainPlanItemList")
    public Result<PageInfo<List<Maintainplanitem>>> selMaintainPlanItemList(@RequestBody SelMaintainPlanItemListDto dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        LambdaQueryWrapper<Maintainplanitem> wrapper = new LambdaQueryWrapper<>();
        if(dto.getMpitype() != null && dto.getMpitype().size() > 0) {
            wrapper.in(Maintainplanitem::getMpitype, dto.getMpitype());
        }
        if(StringUtils.isNotEmpty(dto.getMpicontent())) wrapper.like(Maintainplanitem::getMpicontent, dto.getMpicontent());
        if(StringUtils.isNotEmpty(dto.getMpiname())) wrapper.like(Maintainplanitem::getMpiname, dto.getMpiname());
        if(StringUtils.isNotEmpty(dto.getMpiid())) wrapper.like(Maintainplanitem::getMpiid, dto.getMpiid());
        if(StringUtils.isNotEmpty(dto.getMpiremark())) wrapper.like(Maintainplanitem::getMpiremark, dto.getMpiremark());
        if(StringUtils.isNotEmpty(dto.getMpistatus())) wrapper.eq(Maintainplanitem::getMpistatus, dto.getMpistatus());
        if(StringUtils.isNotEmpty(dto.getMpiResultType())) wrapper.eq(Maintainplanitem::getMpiresulttype, dto.getMpiResultType());
        if(StringUtils.isNotEmpty(dto.getMpiidOrName())) {
            wrapper.like(Maintainplanitem::getMpiname, dto.getMpiidOrName())
                    .or().like(Maintainplanitem::getMpiid, dto.getMpiidOrName());
        }
        List<Maintainplanitem> maintainplanitemList = maintainplanitemMapper.selectList(wrapper);
        // 查询所有的登录用户，set到创建人中（创建人不用编号，直接用名称）
        List<Dscma> dscmas = dscmaMapper.selectList(null);
        Map<String, String> dscmaMap = new HashMap<>();
        for(Dscma dscma : dscmas) {
            dscmaMap.put(dscma.getMa001().trim(), dscma.getMa002());
        }
        for(Maintainplanitem t : maintainplanitemList) {
            if(StringUtils.isNotEmpty(t.getMpicreator())) t.setMpicreator(dscmaMap.get(t.getMpicreator()));
        }
        PageInfo<List<Maintainplanitem>> pageInfo = new PageInfo(maintainplanitemList);
        return Result.success(pageInfo);
    }

    @Log("删除计划项目（点检项目，保养项目，维修项目）")
    @ApiOperation("删除计划项目（点检项目，保养项目，维修项目）")
    @PostMapping("delMaintainPlanItem")
    @DSTransactional
    public Result delMaintainPlanItem(@RequestBody DelMaintainPlanItemDto dto) {
        if(dto.getMpiuuid() == null || dto.getMpiuuid() == 0) {
            return Result.error("mpiUuid不能为空!");
        }
        maintainplanitemMapper.deleteById(dto.getMpiuuid());
        return Result.success();
    }

    @Log("编辑计划项目（点检项目，保养项目，维修项目）")
    @ApiOperation("编辑计划项目（点检项目，保养项目，维修项目）")
    @PostMapping("editMaintainPlanItem")
    @DSTransactional
    public Result editMaintainPlanItem(@RequestBody EditMaintainPlanItemDto dto) {
        Maintainplanitem maintainplanitem = new Maintainplanitem();
        BeanUtils.copyPropertiesIgnoreCase(dto, maintainplanitem);
        maintainplanitem.setMpieditor(SecurityUtils.getLoginUser().getUsername());
        maintainplanitem.setMpiedittime(TimeUtils.getFullNowTime());
        maintainplanitemMapper.updateById(maintainplanitem);
        return Result.success("编辑计划项目完成");
    }

    @Log("保存计划规则（点检项目，保养项目，维修项目）")
    @ApiOperation("保存计划规则（点检项目，保养项目，维修项目）")
    @PostMapping("saveMaintainPlanRule")
    @DSTransactional
    public Result saveMaintainPlanRule(@RequestBody SaveMaintainPlanRuleDto dto) {
        Maintainplanrule maintainplanrule = new Maintainplanrule();
        BeanUtils.copyPropertiesIgnoreCase(dto, maintainplanrule);
        maintainplanrule.setMprcreator(SecurityUtils.getLoginUser().getUsername());
        maintainplanrule.setMprcreationtime(TimeUtils.getFullNowTime());
        maintainplanruleMapper.insert(maintainplanrule);
        return Result.success("规则保存成功");
    }

    @Log("修改计划规则")
    @ApiOperation("修改计划规则")
    @DSTransactional
    @PostMapping("editMaintainPlanRule")
    public Result editMaintainPlanRule(@RequestBody EditMaintainPlanRuleDto dto) {
        Maintainplanrule maintainplanrule = new Maintainplanrule();
        BeanUtils.copyPropertiesIgnoreCase(dto, maintainplanrule);
        maintainplanrule.setMpreditor(SecurityUtils.getLoginUser().getUsername());
        maintainplanrule.setMpredittime(TimeUtils.getFullNowTime());
        maintainplanruleMapper.updateById(maintainplanrule);
        return Result.success("修改计划规则");
    }

    @Log("删除计划规则")
    @ApiOperation("删除计划规则")
    @DSTransactional
    @PostMapping("delMaintainPlanRule")
    public Result delMaintainPlanRule(@RequestBody DelMaintainPlanRuleDto dto) {
        if(dto.getMprUuid() == null || dto.getMprUuid() == 0) {
            return Result.error("mprUuid不能为空!");
        }
        maintainplanruleMapper.deleteById(dto.getMprUuid());
        return Result.success();
    }

    @ApiOperation("计划规则列表")
    @PostMapping("selMaintainPlanRuleList")
    public Result<PageInfo<List<Maintainplanrule>>> selMaintainPlanRuleList(@RequestBody SelMaintainPlanRuleListDto dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        List<Maintainplanrule> maintainplanrules = maintainplanruleMapper.selectList(null);
        PageInfo<List<Maintainplanrule>> pageInfo = new PageInfo(maintainplanrules);
        return Result.success(pageInfo);
    }

    @Log("保存计划类")
    @ApiOperation("保存计划类")
    @DSTransactional
    @PostMapping("saveMaintainPlan")
    public Result saveMaintainPlan(@RequestBody SaveMaintainPlanDto dto) {
        Maintainplan maintainplan = new Maintainplan();
        BeanUtils.copyPropertiesIgnoreCase(dto, maintainplan);
        maintainplan.setMpcreationtime(TimeUtils.getFullNowTime());
        maintainplan.setMpcreator(SecurityUtils.getLoginUser().getUsername());
        maintainplanMapper.insert(maintainplan);
        if(maintainplan.getMpuuid() == null) {
            throw new CustomException("500", "插入完UUID，MP不返回");
        }
        if(dto.getMpiUUIDLIst() != null && dto.getMpiUUIDLIst().size() > 0) {
            List<MaintainplanMaintainplanitem> list = new ArrayList<>();
            for(Integer t : dto.getMpiUUIDLIst()) {
                list.add(new MaintainplanMaintainplanitem(null, maintainplan.getMpuuid(), t));
            }
            maintainplanMaintainplanitemService.saveBatch(list);
        }
        if(dto.getMprUUIDLIst() != null && dto.getMprUUIDLIst().size() > 0) {
            List<MaintainplanMaintainplanrule> list = new ArrayList<>();
            for(Integer t : dto.getMprUUIDLIst()) {
                list.add(new MaintainplanMaintainplanrule(null, maintainplan.getMpuuid(), t));
            }
            maintainplanMaintainplanruleService.saveBatch(list);
        }
        return Result.success("保存计划类");
    }

    @Log("编辑计划类")
    @ApiOperation("编辑计划类")
    @PostMapping("editMaintainPlan")
    @DSTransactional
    public Result editMaintainPlan(@RequestBody EditMaintainPlanDto dto) {
        if(dto.getMpuuid() == null || dto.getMpuuid() == 0) {
            throw new CustomException("500", "UUID为空");
        }
        Maintainplan maintainplan = new Maintainplan();
        BeanUtils.copyPropertiesIgnoreCase(dto, maintainplan);
        maintainplan.setMpedittime(TimeUtils.getFullNowTime());
        maintainplan.setMpcreator(SecurityUtils.getLoginUser().getUsername());
        maintainplanMapper.updateById(maintainplan);
        maintainplanMaintainplanitemMapper.delete(new LambdaQueryWrapper<MaintainplanMaintainplanitem>()
                .eq(MaintainplanMaintainplanitem::getMpuuid, dto.getMpuuid()));
        if(dto.getMpiUUIDLIst() != null && dto.getMpiUUIDLIst().size() > 0) {
            List<MaintainplanMaintainplanitem> list = new ArrayList<>();
            for(Integer t : dto.getMpiUUIDLIst()) {
                MaintainplanMaintainplanitem maintainplanMaintainplanitem = new MaintainplanMaintainplanitem(UUID.randomUUID().toString(), maintainplan.getMpuuid(), t);
//                maintainplanitemMapper.insert(maintainplanMaintainplanitem);
                list.add(maintainplanMaintainplanitem);
            }
            maintainplanMaintainplanitemService.saveBatch(list);
        }
/*        if(dto.getMprUUIDLIst() != null && dto.getMprUUIDLIst().size() > 0) {
            maintainplanMaintainplanruleMapper.delete(new LambdaQueryWrapper<MaintainplanMaintainplanrule>()
                    .eq(MaintainplanMaintainplanrule::getMpuuid, dto.getMpuuid()));
            List<MaintainplanMaintainplanrule> list = new ArrayList<>();
            for(Integer t : dto.getMprUUIDLIst()) {
                list.add(new MaintainplanMaintainplanrule(null, maintainplan.getMpuuid(), t));
            }
        }*/
        return Result.success("编辑计划类");
    }

    @ApiOperation("计划类列表")
    @PostMapping("selMaintainPlanList")
    public Result<List<SelMaintainPlanListVo>> selMaintainPlanList(@RequestBody SelMaintainPlanListDto dto) {
//        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        List<SelMaintainPlanListVo> list = maintainplanMapper.selMaintainPlanList(dto);
//        PageInfo<List<SelMaintainPlanListVo>> pageInfo = new PageInfo(list);
        // 查询所有的登录用户，set到创建人中（创建人不用编号，直接用名称）
        List<Dscma> dscmas = dscmaMapper.selectList(null);
        Map<String, String> dscmaMap = new HashMap<>();
        for(Dscma dscma : dscmas) {
            dscmaMap.put(dscma.getMa001().trim(), dscma.getMa002());
        }
        for(SelMaintainPlanListVo t : list) {
            if(StringUtils.isNotEmpty(t.getMpcreator())) t.setMpcreator(dscmaMap.get(t.getMpcreator()));
            t.setRuleList(maintainplanruleMapper.selListByMpuuid(t.getMpuuid()));
            t.setItemList(maintainplanitemMapper.selListByMpuuid(t.getMpuuid()));
        }
        return Result.success(list);
    }

    @Log("删除计划类")
    @ApiOperation("删除计划类")
    @PostMapping("delMaintainPlan/{id}")
    @DSTransactional
    public Result delMaintainPlan(@PathVariable Integer id) {
        maintainplanMapper.delete(new LambdaQueryWrapper<Maintainplan>().eq(Maintainplan::getMpuuid, id));
        return Result.success();
    }

    @Log("保存方案组")
    @ApiOperation("保存方案组")
    @PostMapping("saveMaintainPlanGroup")
    @DSTransactional
    public Result saveMaintainPlanGroup(@RequestBody SaveMaintainPlanGroupDto dto) {
        Maintainplangroup maintainplangroup = new Maintainplangroup();
        BeanUtils.copyPropertiesIgnoreCase(dto, maintainplangroup);
        maintainplangroup.setMpgcreator(SecurityUtils.getLoginUser().getUsername());
        maintainplangroup.setMpgcreationtime(TimeUtils.getFullNowTime());
        maintainplangroupMapper.insert(maintainplangroup);
        if(maintainplangroup.getMpguuid() == null) {
            throw new CustomException("500", "fdsfsdafsdafsdaf");
        }
        if(dto.getMaintainPlanIdList() != null && dto.getMaintainPlanIdList().size() > 0) {
            List<MaintainplangroupMaintainplan> list = new ArrayList<>();
            for(Integer t : dto.getMaintainPlanIdList()) {
                list.add(new MaintainplangroupMaintainplan(null, maintainplangroup.getMpguuid(), t));
            }
            maintainplangroupMaintainplanService.saveBatch(list);
        }
        return Result.success("保存方案组");
    }

    @Log("编辑方案组")
    @ApiOperation("编辑方案组")
    @PostMapping("editMaintainPlanGroup")
    @DSTransactional
    public Result editMaintainPlanGroup(@RequestBody EditMaintainPlanGroupDto dto) {
        Maintainplangroup maintainplangroup = new Maintainplangroup();
        BeanUtils.copyPropertiesIgnoreCase(dto, maintainplangroup);
        maintainplangroup.setMpgcreator(SecurityUtils.getLoginUser().getUsername());
        maintainplangroup.setMpgcreationtime(TimeUtils.getFullNowTime());
        maintainplangroupMapper.updateById(maintainplangroup);
        if(maintainplangroup.getMpguuid() == null) {
            throw new CustomException("500", "编辑方案组UUID不能为空");
        }
        if(dto.getMaintainPlanIdList() != null && dto.getMaintainPlanIdList().size() > 0) {
            maintainplangroupMaintainplanMapper.delete(new LambdaQueryWrapper<MaintainplangroupMaintainplan>()
                    .eq(MaintainplangroupMaintainplan::getMpuuid, dto.getMpguuid()));
            List<MaintainplangroupMaintainplan> list = new ArrayList<>();
            for(Integer t : dto.getMaintainPlanIdList()) {
                list.add(new MaintainplangroupMaintainplan(null, dto.getMpguuid(), t));
            }
            maintainplangroupMaintainplanService.saveBatch(list);
        }
        return Result.success("编辑方案组");
    }

    @ApiOperation("方案组列表")
    @PostMapping("selMaintainPlanGroup")
    public Result<List<Maintainplangroup>> selMaintainPlanGroup(@RequestBody SelMaintainPlanGroupDto dto) {
        LambdaQueryWrapper<Maintainplangroup> wrapper = new LambdaQueryWrapper<>();
        if(StringUtils.isNotEmpty(dto.getMpgtype())) wrapper.eq(Maintainplangroup::getMpgtype, dto.getMpgtype());
        if(StringUtils.isNotEmpty(dto.getMpgidOrName())) {
            wrapper.like(Maintainplangroup::getMpgid, dto.getMpgidOrName())
                    .or().like(Maintainplangroup::getMpgname, dto.getMpgidOrName());
        }
        List<Maintainplangroup> maintainplangroupList = maintainplangroupMapper.selectList(wrapper);
        for(Maintainplangroup t : maintainplangroupList) {
            t.setMacGroupList(maintainplangroupResourcegroupMapper.selectList(new LambdaQueryWrapper<MaintainplangroupResourcegroup>()
                    .eq(MaintainplangroupResourcegroup::getMpguuid, t.getMpguuid())));
        }
        return Result.success(maintainplangroupList);
    }

    @Log("删除方案组")
    @ApiOperation("删除方案组")
    @DSTransactional
    @PostMapping("delMaintainPlanGroup")
    public Result delMaintainPlanGroup(@RequestBody DelMaintainPlanGroupDto dto) {
        if(dto.getMpgUuid() == null || dto.getMpgUuid() == 0) {
            return Result.error("mpgUuid不能为空!");
        }
        maintainplangroupMapper.deleteById(dto.getMpgUuid());
        return Result.success("删除成功");
    }

    @Log("保存方案组和机器的配置")
    @ApiOperation("保存方案组和机器的配置")
    @DSTransactional
    @PostMapping("saveMainPlanGroup_ResourceGrup")
    public Result saveMainPlanGroup_ResourceGrup(@RequestBody SaveMainPlanGroup_ResourceGrupDto dto) {
        if(dto.getMpguuid() == null || dto.getMpguuid() == 0) {
            return Result.error("mpiUuid不能为空!");
        }
        maintainplangroupResourcegroupMapper.delete(new LambdaQueryWrapper<MaintainplangroupResourcegroup>().eq(MaintainplangroupResourcegroup::getMpguuid, dto.getMpguuid()));
        if(dto.getItemList() != null) {
            for(SaveMainPlanGroup_ResourceGrupItemDto t : dto.getItemList()) {
                MaintainplangroupResourcegroup y = new MaintainplangroupResourcegroup();
                y.setMpguuid(dto.getMpguuid());
                y.setResourcegroupid(t.getResourcegroupid());
                y.setResourcegroupno(t.getResourcegroupno());
                y.setResourcegroupname(t.getResourcegroupname());
                maintainplangroupResourcegroupMapper.insert(y);
            }
        }
        return Result.success("");
    }

    @Log("新增维修|保养单")
    @ApiOperation("新增维修|保养单")
    @DSTransactional
    @PostMapping("saveRepairDocument")
    public Result saveRepairDocument(@RequestBody SaveRepairDocumentDto dto) {
        if(StringUtils.isEmpty(dto.getTE004())) {
            return Result.error("repairDocType不能为空, 0.维修单 1.保养单.");
        }
        Eqtte eqtte = new Eqtte();
        BeanUtils.copyPropertiesIgnoreCase(dto, eqtte);
        if("0".equals(dto.getTE004().trim())) eqtte.setTE001("WXD");
        else if ("1".equals(dto.getTE004().trim())) eqtte.setTE001("BYD");
        else if("2".equals(dto.getTE004().trim())) eqtte.setTE001("DJD");
        eqtte.setTE002(eqtteMapper.selTe002(eqtte.getTE001()));
        eqtte.setTE003(TimeUtils.HZStdTime());
        eqtte.setTE019("0");
        eqtte.setCREATE_DATE(TimeUtils.getFullNowTime());
        eqtte.setCREATOR(SecurityUtils.getLoginUser().getUsername());
        List<Eqttf> eqttfList = new ArrayList<>();
        if(dto.getItemList() == null || dto.getItemList().size() == 0) {
            return Result.error("单身不能为空!");
        }
        int idx = 1;
        for(SaveRepairDocumentItemDto t : dto.getItemList()) {
            Eqttf eqttf = new Eqttf();
            eqttf.setTF001(eqtte.getTE001());
            eqttf.setTF002(eqtte.getTE002());
            eqttf.setTF003(""+idx);  idx++;
            BeanUtils.copyPropertiesIgnoreCase(t, eqttf);
            eqttfList.add(eqttf);
            eqttf.setCREATE_DATE(TimeUtils.getNowTime());
            eqttf.setCREATOR(SecurityUtils.getLoginUser().getUsername());
        }
        eqtteMapper.insert(eqtte);
        eqttfService.saveBatch(eqttfList);
        return Result.success("新增成功, 单号: " + eqtte.getTE002());
    }

    @Log("维修|保养单保存结果")
    @ApiOperation("维修|保养单保存结果")
    @DSTransactional
    @PostMapping("saveRepairDocumentResult")
    public Result saveRepairDocumentResult(@RequestBody SaveRepairDocumentResultDto dto) {
        Eqtte eqtte = new Eqtte();
        BeanUtils.copyPropertiesIgnoreCase(dto, eqtte);
        eqtte.setMODI_DATE(TimeUtils.getFullNowTime());
        eqtte.setMODIFIER(SecurityUtils.getLoginUser().getUsername());
        List<Eqttf> eqttfList = new ArrayList<>();
        if(dto.getList() == null || dto.getList().size() == 0) {
            return Result.error("单身不能为空!");
        }
        eqtteMapper.update(eqtte, new LambdaQueryWrapper<Eqtte>()
                .eq(Eqtte::getTE001, dto.getTE001()).eq(Eqtte::getTE002, dto.getTE002()));
        for(SaveRepairDocumentResultItemDto t : dto.getList()) {
            Eqttf eqttf = new Eqttf();
            BeanUtils.copyPropertiesIgnoreCase(t, eqttf);
            eqttfList.add(eqttf);
            eqttf.setMODI_DATE(TimeUtils.getNowTime());
            eqttf.setMODIFIER(SecurityUtils.getLoginUser().getUsername());
            eqttfMapper.update(eqttf, new LambdaQueryWrapper<Eqttf>()
                    .eq(Eqttf::getTF001, t.getTF001()).eq(Eqttf::getTF002, t.getTF002()).eq(Eqttf::getTF003, t.getTF003()));
        }
        return Result.success("保存结果成功");
    }

    @Log("维修|保养单删除")
    @ApiOperation("维修|保养单删除")
    @DSTransactional
    @PostMapping("delRepairDocument")
    public Result delRepairDocument(@RequestBody DelRepairDocumentDto dto) {
        eqtteMapper.delete(new LambdaQueryWrapper<Eqtte>().eq(Eqtte::getTE001, dto.getDocSingle()).eq(Eqtte::getTE002, dto.getDocNo()));
        eqttfMapper.delete(new LambdaQueryWrapper<Eqttf>().eq(Eqttf::getTF001, dto.getDocSingle()).eq(Eqttf::getTF002, dto.getDocNo()));
        return Result.success("删除成功");
    }

    @ApiOperation("维修|保养单列表")
    @PostMapping("repairDocumentList")
    public Result<PageInfo<List<Eqtte>>> repairDocumentList(@RequestBody RepairDocumentListDto dto) {

        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());

        LambdaQueryWrapper<Eqtte> wrapper = new LambdaQueryWrapper<>();
        if(StringUtils.isNotEmpty(dto.getRepairDocType())) wrapper.eq(Eqtte::getTE004, dto.getRepairDocType());
        if(StringUtils.isNotEmpty(dto.getMacNo())) wrapper.like(Eqtte::getTE011, dto.getMacNo());
        if(StringUtils.isNotEmpty(dto.getMacName())) wrapper.like(Eqtte::getTE012, dto.getMacName());
        if(StringUtils.isNotEmpty(dto.getDocSingle())) wrapper.eq(Eqtte::getTE001, dto.getDocSingle());
        if(StringUtils.isNotEmpty(dto.getDocNo())) wrapper.eq(Eqtte::getTE002, dto.getDocNo());
        List<Eqtte> eqtteList = eqtteMapper.selectList(wrapper);
        PageInfo<List<Eqtte>> pageInfo = new PageInfo(eqtteList);
        for(Eqtte eqtte : eqtteList) {
            eqtte.setDanshenList(eqttfMapper.selectList(new LambdaQueryWrapper<Eqttf>()
                    .eq(Eqttf::getTF001, eqtte.getTE001()).eq(Eqttf::getTF002, eqtte.getTE002())));
        }
        return Result.success(pageInfo);
    }

    @ApiOperation("点检单详情")
    @PostMapping("dianJianDanDetail")
    public Result<Eqtte> repairDocumentList(@RequestBody DianJianDanDetailDto dto) {
        Eqtte eqtte = eqtteMapper.selectOne(new LambdaQueryWrapper<Eqtte>().eq(Eqtte::getTE062, dto.getJinzhanUuid()));
        if(eqtte == null) {
            throw new CustomException("500", "点检单不存在");
        }
        List<Eqttf> eqttfList = eqttfMapper.selectList(new LambdaQueryWrapper<Eqttf>().eq(Eqttf::getTF001, eqtte.getTE001()).eq(Eqttf::getTF002, eqtte.getTE002()));
        eqtte.setDanshenList(eqttfList);
        return Result.success(eqtte);
    }

}
